C
C     ..................................................................
C
C        SUBROUTINE SRATE
C
C        PURPOSE
C           TO COMPUTE THE PROPORTION OF SUBJECTS SURVIVING, THE
C           SURVIVAL RATES AND THE STANDARD ERRORS FOR SUCCESSIVELY
C           REDUCED TIME PERIODS.  THE SURVIVAL RATE IS COMPUTED FOR
C           EACH OF K PERIODS, WHERE K IS A CONSTANT TO BE SPECIFIED AND
C           IS LESS THAN OR EQUAL TO N (WHERE N = TOTAL NUMBER OF
C           PERIODS).
C
C        USAGE
C           CALL SRATE (N,K,X,IE)
C
C        DESCRIPTION OF PARAMETERS
C           N - THE TOTAL NUMBER OF PERIODS AFTER TREATMENT OR DIAGNOSIS
C           K - THE SPECIFIED PERIOD UP TO WHICH SURVIVAL RATES ARE TO
C               BE CALCULATED
C           X - AN INPUT AND OUTPUT MATRIX (N X 9) CONTAINING THE
C               FOLLOWING INFORMATION
C               FOR INPUT--STORED IN THE N ROWS OF EACH COLUMN
C                  COL 1 - NUMBER OF SUBJECTS ALIVE AT THE BEGINNING OF
C                          PERIOD
C                  COL 2 - NUMBER OF SUBJECTS WHICH DIED DURING THE
C                          PERIOD
C                  COL 3 - NUMBER OF SUBJECTS LOST TO FOLLOW-UP DURING
C                          THE PERIOD
C                  COL 4 - NUMBER OF SUBJECTS WITHDRAWN ALIVE DURING THE
C                          PERIOD
C                    FOR OUTPUT--STORED IN THE FIRST K ROWS OF EACH
C                    COLUMN
C                  COL 5 - EFFECTIVE NUMBER EXPOSED TO THE RISK OF DYING
C                  COL 6 - PROPORTION WHO DIED DURING THE PERIOD
C                  COL 7 - PROPORTION WHO SURVIVED DURING THE PERIOD
C                  COL 8 - SURVIAL RATE
C                  COL 9 - STANDARD ERROR OF THE SURVIVAL RATE
C           IE- 1, IF K IS NOT IN THE CLOSED INTERVAL (0,N).
C               2, IF THE NUMBER OF SUBJECTS ALIVE AT THE BEGINNING
C               OF PERIOD I IS LESS THAN THE SUM OF THOSE WHICH DIED,
C               WERE LOST, OR WERE WITHDRAWN DURING PERIOD I (I=1,...N)
C               3, IF THE NUMBER OF SUBJECTS WHICH DIED, WERE LOST, OR
C               WERE WITHDRAWN IN PERIOD I IS NOT EQUAL TO THE NUMBER
C               ALIVE AT THE BEGINNING OF PERIOD I LESS THE NUMBER
C               ALIVE AT THE BEGINNING OF PERIOD I + 1 (I=1,...N-1)
C
C        REMARKS
C           IF THE SUBJECTS IN A GIVEN GROUP ARE ALL DIAGNOSED OR
C           TREATED AT THE SAME TIME, THE CONSTANT K MAY BE SET EQUAL TO
C           N .  IF THE SUBJECTS IN A GIVEN GOUP ENTER THE STUDY AT
C           VARYING TIMES, K CAN BE NO GREATER THAN N-1.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NONE
C
C        METHOD
C           REFER TO S. J. CUTLER AND F. EDERER 'MAXIMUM UTILIZATION OF
C           THE LIFE TABLE METHOD IN ANALYZING SURVIVAL', JOURNAL OF
C           CHRONIC DISEASES, DECEMBER, 1958.  PP 699-712.
C
C     ..................................................................
C
      SUBROUTINE SRATE (N,K,X,IE)
C
      DIMENSION X(1)
C
C        INITIALIZATION AND ERROR CHECKING
C
      IE=0
      NP4=4*N+1
      NP9=NP4+NP4+N-2
      DO 1 I=NP4,NP9
    1 X(I)=0.0
      IF (K) 2,2,3
    2 IE=1
      GO TO 45
    3 IF(K-N) 4,4,2
    4 DO 9 I=1,N
      NP4=I+N
      NP9=NP4+N
      NP1=NP9+N
      IF(INT(X(I)-X(NP4)-X(NP9)-X(NP1)+.01)) 5,6,6
    5 IE=2
      GO TO 45
    6 IF(I-N) 7,9,9
    7 IF (INT(X(I+1)-X(I)+X(NP4)+X(NP9)+X(NP1)+.01)) 8,9,8
    8 IE=3
        GO TO 45
    9 CONTINUE
   15 L1=0
      L2=L1+N
      L3=L2+N
      L4=L3+N
      L5=L4+N
      L6=L5+N
      L7=L6+N
      L8=L7+N
      L9=L8+N
      LD=L2
      LE=L5
      LQ=L6
      SUM=0.0
C
      DO 40 I=1,K
C
C        COMPUTE EFFECTIVE NUMBER EXPOSED TO RISK OF DYING
C
      L1=L1+1
      L3=L3+1
      L4=L4+1
      L5=L5+1
      X(L5)=X(L1)-(X(L3)+X(L4))/2.0
C
C        COMPUTE PROPORTION OF DYING
C
      L2=L2+1
      L6=L6+1
      X(L6)=X(L2)/X(L5)
C
C        COMPUTE PROPORTION OF SURVIVING
C
      L7=L7+1
      X(L7)=1.0-X(L6)
C
C        COMPUTE SURVIVAL RATE
C
      L8=L8+1
      IF (I-1) 20, 20, 25
   20 X(L8)=X(L7)
      GO TO 30
   25 X(L8)=X(L8-1)*X(L7)
C
C        COMPUTE STANDARD ERROR OF SURVIVAL RATE
C
   30 L9=L9+1
      SUM=SUM+X(L6)/(X(L5)-X(L2))
   40 X(L9)=X(L8)*SQRT(SUM)
C
   45 RETURN
      END
